//
//  WBComposeView.swift
//  GitWeibo
//
//  Created by 胡金东 on 2017/6/15.
//  Copyright © 2017年 胡金东. All rights reserved.
//

import UIKit

class WBComposeView: UIView {
    
    class func composeView() -> WBComposeView {
        
        /// - xib创建布局时候用这种方法
        let nib = UINib(nibName: "WBComposeView", bundle: nil)
        let v = nib.instantiate(withOwner: nil, options: nil)[0] as! WBComposeView
        
        v.frame = UIScreen.main.bounds
        
        return v
        
    }
    
/// - 纯代码布局时候用的
//    override init(frame: CGRect) {
//        super.init(frame: UIScreen.main.bounds)
//        backgroundColor = UIColor.red
//    }
//    
//    required init?(coder aDecoder: NSCoder) {
//        fatalError("init(coder:) has not been implemented")
//    }
    
    func show()  {
        /// - 将当前视图添加到根视图控制器的view上
        guard let vc = UIApplication.shared.keyWindow?.rootViewController else {
            return
        }
        /// - 添加视图
        vc.view.addSubview(self)
    }
    
    override func awakeFromNib() {
        
        setUpUI()
    }
    
    @objc func composeBtnClick(){
        print("点击了文字")
    }

}


extension WBComposeView {
    func setUpUI()  {
        let btn = WBComposeTypeButton.compostTypeButton(imageName: "tabbar_compose_idea", title: "文字")
        
        btn.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
        addSubview(btn)
        
        btn.addTarget(self, action: #selector(composeBtnClick), for: .touchUpInside)
        
    }
}
